import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 龙行
 **/
export default class WS_DragonFly extends AbilityBase {
    static instance: WS_DragonFly;
    buffType: AppBuffType = {
        id: 'buff_WS_DragonFly',
        art: this.art,
        name: this.abilityName,
        ubertip: '减速效果',
        attribute: {
            attackSpd_p: -0.2,
            move_speed_p: -0.2,
        },
        dur: 4,
    };
    constructor(id: string = 'Alx1') {
        super(id);
        WS_DragonFly.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        MovementCommon.hitFly({
            distance: 600,
            time: 0.6,
            angle: GetUnitFacing(source),
            target: source,
            caster: source,
            maxHeight: 0,
            onInterval: this.effectInterval.bind(this),
            onEnd: this.onEnd.bind(this),
        });
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl', source, 'overhead'));
        this.pool.set(source, []);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    pool: Map<unit, unit[]> = new Map();
    effectInterval(p: HitFlyConfig) {
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 175);
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 28 * lv + UnitCommon.取法强(p.caster) * (0.5 + 0.5 * lv);
        let pool = this.pool.get(p.caster);
        for (let e of es) {
            let ag = MathUtil.angleBetweenCoords(p.curX, p.curY, GetUnitX(e), GetUnitY(e));
            if (pool.includes(e)) continue;
            MovementCommon.hitFly({
                distance: 250,
                angle: ag,
                time: 0.5,
                maxHeight: 200,
                target: e,
                caster: p.caster,
            });
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Human\\StormBolt\\StormBoltMissile.mdl', e, 'origin'));
            pool.push(e);
            // BuffUtil.addBuff(e, this.buffType.id, p.caster);
            BuffCommon.addBuff({ target: e, caster: p.caster, buffTypeId: this.buffType.id, ablityId: this.id });
            DamageSystemInstance.applyWindDamage(e, p.caster, dmg, this.id);
        }
    }
    onEnd(p: HitFlyConfig) {
        this.pool.delete(p.caster);
    }
}
